package com.woniuxy.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import com.woniuxy.pojo.FindRoom;
import com.woniuxy.pojo.Room;
import com.woniuxy.pojo.Room_yyh;

import com.woniuxy.pojo.RoomType;
import com.woniuxy.pojo.RoomType_dgy;
import com.woniuxy.pojo.Room_dgy;
import com.woniuxy.provider.FindRoomProvider;
import com.woniuxy.provider.RoomProvider;

public interface RoomMapper {
	
	@Select("select * from room where rtid=(select rtid from roomtype where rtname = #{roomType})")
	public List<Room> findByType(String roomType);
	
	@Select("select * from room,roomtype where room.rtid=roomtype.rtid")
	public List<Room_yyh> getAll();
	
	@Update("update room set rstate=#{rstate} where rid=#{rid}")
	public int updateR(Room room);
	
	@Delete("Delete  from room where rid=#{rid}")
	public int deleteR(int rid);

	@Insert("insert into room values(default,#{rtid},#{rstate})")
	public int insertR(Room room);
	//根据房间类型和服务查询对应房间
	List<Room> findTypeandfw();
	//模糊查询
	@SelectProvider(type=FindRoomProvider.class,method="findRooms")
	public List<Room> findStudents(FindRoom findRoom);

	@Select("select * from room where rstate=#{rstate}")
	public List<Room> findByState(String rstate);

	
	@Select("select imgpath from roomimg where rtid=#{rtid} limit 1")
	public String findRoomHeadImg(int rtid);
	
	@Select("select rtname from room INNER JOIN roomtype ON room.rtid=roomtype.rtid where rid=#{rid}")
	public String findRtName(int rid);

	@Select("select * from room,(SELECT * FROM roomtype where rtname like #{message} or rwindow like #{message} or rfood like #{message} or rspring like #{message} or rmessage like #{message} or rprice like #{message}) dd where room.rtid=dd.rtid")
	public List<Room_yyh> selectR(String message);

	//查询每个房间类型的个数
	@Select("SELECT COUNT(*),rtid FROM room GROUP BY rtid;")
	public Map<Integer, Integer>  findRoomCount();

	@Select("select rtname from roomtype where rtid=#{rtid}")
	public String fingRtName(int rtid);

	@Select("select * from room where rtid=#{rtid} and rstate='可入住'")
	public Room_dgy findById(int rid);

	@Select("select * from room")
	public List<Room_dgy> findRoom(String checkIn, String checkOut);

	@Update("update room set rstate=#{rstate} where rid=#{rid}")
	public int updateRoomState(Room_dgy room);

	@Select("select * from room where rtid=(select rtid from roomtype where rtname = #{rtname})"
			+ " and rstate='可入住'")
	public List<Room_dgy> findByType1(RoomType_dgy roomType);
	
	@Select("select * from room where rid=#{rid} ")
	public Room_dgy findone(int rid);

}
